home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.03 Mar 90 / MultiFinder Test / test program < prev    next >
Encoding:
Text File  |  1989-08-30  |  3.2 KB  |  126 lines  |  [TEXT/PJMM]

  1. program test;
  2.  
  3. procedure debugBanner (msg: Str255);
  4.     const
  5.         numTicks = 1 * 60; { seconds * ticks/sec }
  6.         kResWIND128 = 128; { WIND resource }
  7.     var
  8.         discard: LongInt;
  9.         banner: WindowPtr;
  10.         oldPort: GrafPtr;
  11.         lineWidth: Integer;
  12.     begin
  13.         GetPort(oldPort);
  14.         banner := GetNewWindow(kResWIND128, nil, Pointer(-1));
  15.         if banner <> nil then
  16.             begin
  17.                 ShowWindow(banner);        { make the window visible }
  18.                 SetPort(banner);
  19.                 PenNormal;
  20.                 ClipRect(banner^.portRect);
  21. {$R-}
  22.                 lineWidth := TextWidth(QDPtr(@msg[1]), 0, Integer(msg[0]));
  23. {$R+}
  24.                 with banner^.portRect do
  25.                     MoveTo(((right - left) - lineWidth) div 2, (bottom - top) div 2);
  26. {$R-}
  27.                 DrawText(QDPtr(@msg[1]), 0, Integer(msg[0]));
  28. {$R+}
  29.                 Delay(numTicks, discard);    { wait a while }
  30.                 DisposeWindow(banner);    { get rid of window }
  31.             end;
  32.         SetPort(oldPort);
  33.     end; { debugBanner }
  34.  
  35. function hasWaitNextEvent: Boolean;
  36. { determines if hardware has WNE trap }
  37.     const
  38.         kVersRequested = 2;        { as of 6.0.1 }
  39.         kWaitNextEventTrap = $A860;    { determines presence of WaitNextEvent }
  40.  
  41. { system error constants that are missing from THINK interface }
  42.         envBadVers = -5501;
  43.         envVersTooBig = -5502;
  44.  
  45.     type
  46.         pInteger = ^Integer;
  47.  
  48.     var
  49.         result: OSErr;
  50.         theRec: SysEnvRec;
  51.         theRecPtr: ^SysEnvRec;
  52.  
  53.     function GetTrapType (theTrap: Integer): TrapType;
  54.         const
  55.             kOSTrapMask = $0F00; { OS traps start with A0, Tool with A8 or AA. }
  56.         begin
  57.             if BAND(theTrap, $0F00) = 0 then
  58.                 GetTrapType := OSTrap
  59.             else
  60.                 GetTrapType := ToolTrap;
  61.         end; {GetTrapType}
  62.  
  63.     function TrapExists (theTrap: Integer): Boolean;
  64.         const
  65.             kUnimplementedTrap = $A89F;    { unimplemented trap value }
  66.         begin
  67.             TrapExists := GetTrapAddress(kUnimplementedTrap) <> NGetTrapAddress(theTrap, GetTrapType(theTrap));
  68.         end; {TrapExists}
  69.  
  70.     begin
  71.         hasWaitNextEvent := False;
  72.         theRecPtr := @theRec;
  73.         result := SysEnvirons(kVersRequested, theRecPtr^);
  74.         with theRec do
  75.             case result of
  76.                 envNotPresent: 
  77.                     debugBanner('64k ROMS');
  78.                 envBadVers: 
  79.                     debugBanner('negative version number passed SysEnvirons');
  80.                 envVersTooBig, noErr: 
  81.                     begin    { good environs call, fill related fields }
  82.                         if machineType > envMac then
  83.                             hasWaitNextEvent := TrapExists(kWaitNextEventTrap);
  84.                     end;
  85.             end; { case }
  86.     end; { hasWaitNextEvent }
  87.  
  88. function multiFinderTest: Boolean;
  89. { a little event loop to see if we get mouse-moved events with a tiny region }
  90.     const
  91.         kTries = 10;    { number of events to wait for mouse event }
  92.     var
  93.         mouseRgn: RgnHandle;
  94.         count: Integer;
  95.         gotEvent: Boolean;
  96.         theEvent: EventRecord;
  97.     begin
  98.         multiFinderTest := False;    { assume false }
  99.         if hasWaitNextEvent then { otherwise always false }
  100.             begin
  101.                 debugBanner('has WaitNextEvent');
  102.                 gotEvent := False;
  103.                 count := 1;
  104.                 mouseRgn := NewRgn;    { should be empty region (0,0,0,0) }
  105.                 while (gotEvent = False) and (count < kTries) do
  106.                     begin
  107.                         gotEvent := WaitNextEvent(EveryEvent, theEvent, 0, mouseRgn);
  108.                         if theEvent.what = app4Evt then
  109.                             multiFinderTest := True;
  110.                         count := count + 1;
  111.                     end;
  112.                 DisposeRgn(mouseRgn);
  113.             end;
  114.     end; { multiFinderTest }
  115.  
  116.     var
  117.         multiFinderIsRunning: Boolean;
  118.  
  119. begin
  120.     multiFinderIsRunning := multiFinderTest;
  121.     if multiFinderIsRunning then
  122.         debugBanner('multiFinder running')
  123.     else
  124.         debugBanner('multiFinder not running');
  125.  
  126. end. { test }